import { ColumnProps } from '~/library/components/ProTable/interface'
import { getWaresCategoryListAPI } from '~/src/api/goods'
import { Procure } from '~/src/api/interface/procure'
import { getStoreHouseAPI } from '~/src/api/procure'
import { getLastQuarterDays } from '~/src/utils/date'
import { formatDate } from '~/src/utils/date-formatter'
import { stockStatementType } from '~/src/utils/serviceDict'

export const stockStatementColumn: ColumnProps<Procure.StockStatement>[] = [
  {
    type: 'index',
    label: '序号',
    width: 60,
    search: {
      el: 'date-picker',
      label: '业务日期',
      key: 'date',
      order: 1,
      defaultValue: [formatDate(-getLastQuarterDays(), 'start', 'yyyy-MM-dd'), formatDate(0, 'end', 'yyyy-MM-dd')],
      props: {
        type: 'datetimerange',
        format: 'YYYY-MM-DD',
        valueFormat: 'YYYY-MM-DD',
      },
    },
  },
  {
    sortable: true,
    prop: 'createTime',
    label: '业务日期',
    width: 180,
  },
  {
    sortable: true,
    prop: 'sourceNo',
    label: '单据号',
    width: 160,
    search: {
      el: 'input',
      key: 'sourceNo',
    },
  },
  {
    sortable: true,
    prop: 'barcode',
    label: '条码',
    width: 160,
    search: {
      el: 'input',
      key: 'content',
      placeholder: '请输入商品名称或编码',
      label: '商品',
    },
  },
  {
    sortable: true,
    prop: 'houseName',
    label: '仓库名称',
    enum: () => getStoreHouseAPI({ pageNum: 1, pageSize: 9999 }),
    isFilterEnum: false,
    width: 120,
    fieldNames: { label: 'name', value: 'id' },
    search: {
      el: 'select',
      key: 'houseId',
    },
  },
  {
    sortable: true,
    prop: 'goodsName',
    label: '商品商品',
    width: 130,
    // isFilterEnum: false,
    // fieldNames: { label: "name", value: "id" },
    // enum: () => getInventoryGoodsList({ pageNum: 1, pageSize: 9999 }),
    // search: {
    //   el: "select",
    //   key: "categoryId",
    //   label: "选择商品"
    // }
  },
  {
    sortable: true,
    prop: 'categoryName',
    label: '商品分类',
    width: 110,
    isFilterEnum: false,
    fieldNames: { label: 'name', value: 'id' },
    enum: () => getWaresCategoryListAPI({ pageNum: 1, pageSize: 9999 }),
    search: {
      el: 'tree-select',
      key: 'categoryId',
      label: '商品分类',
    },
  },
  {
    sortable: true,
    prop: 'typeName',
    label: '业务类型',
    enum: stockStatementType,
    isFilterEnum: false,
    search: {
      el: 'select',
      key: 'type',
      label: '单据类型',
    },
    width: 120,
  },
  {
    sortable: true,
    prop: 'unitName',
    label: '单位',
    width: 80,
  },
  {
    sortable: true,
    prop: 'quantity',
    label: '发生数量',
    width: 110,
  },
  {
    sortable: true,
    prop: 'price',
    label: '发生成本',
    width: 110,
  },
  {
    sortable: true,
    prop: 'amount',
    label: '发生金额',
    width: 110,
  },
  {
    sortable: true,
    prop: 'balanceQuantity',
    label: '结余数量',
    width: 110,
  },
  {
    sortable: true,
    prop: 'balancePrice',
    label: '结余成本',
    width: 110,
  },
  {
    sortable: true,
    prop: 'balanceAmount',
    label: '结余金额',
    width: 110,
  },
]
